﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using H2.Streams;

namespace Mystery.SCNR.Scripts
{
    public class ScriptStringData
    {
        public const int Offset = 432;

        public char[] Characters;
        public List<string> List;

        public ScriptStringData(char[] data)
        {
            Characters = data;

            List = new List<string>();
            int startIndex = 0;
            for (int endIndex = 0; endIndex < Characters.Length; endIndex++)
            {
                if (Characters[endIndex] == '\0')
                {
                    List.Add(new string(Characters, startIndex, endIndex - startIndex));
                    startIndex = endIndex + 1;
                }
            }
        }

        public string GetName(uint index)
        {
            uint endIndex = index;
            for (; endIndex < Characters.Length; endIndex++)
                if (Characters[endIndex] == '\0') break;
            return new string(Characters, (int)index, (int)(endIndex - index));
        }

        public static ScriptStringData Read(MapStream map, int scnrOffset)
        {
            return new ScriptStringData(map.ReadChars(map.ReadReflexiveAt(scnrOffset + Offset)));
        }
    }
}
